/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package topcoder;

/**
 *
 * @author Mohamed.Azouz
 */
public class MegaCoolNumbersEasy {

    public int count(int n) {
        int tot = 0;
        for (int i = 1; i <= n; i++) {
            if (this.isMegaCool(i)) {
                tot++;
            }
        }
        return tot;
    }

    private boolean isMegaCool(int n) {
        String s = String.valueOf(n);
        if (s.length() <= 2) {
            return true;
        }
        int diff = Integer.valueOf(s.charAt(1)) - Integer.valueOf(s.charAt(0));
        for (int i = 2; i < s.length(); i++) {
            int diff2 = Integer.valueOf(s.charAt(i)) - Integer.valueOf(s.charAt(i - 1));
            if (diff2 != diff) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        MegaCoolNumbersEasy coolNumbersEasy = new MegaCoolNumbersEasy();
        System.out.println(coolNumbersEasy.count(500));
    }
}
